package com.ghsc.ghxc.jsb.ui.integral.adapter

import android.graphics.Paint
import android.text.TextUtils
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cn.appcore.utils.GlideUtil
import com.flyco.roundview.RoundLinearLayout
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.ui.integral.bean.HomeIntegralBean
import com.ghsc.ghxc.jsb.utils.StringUtil
import com.makeramen.roundedimageview.RoundedImageView

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.integral.adapter
 * 类名：IntegralCommodityAdapter
 * 创建时间：2024/5/21 16:29
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class IntegralCommodityAdapter(width:Float)    : BaseQuickAdapter<HomeIntegralBean, BaseViewHolder>(
    R.layout.home_integral_list_item) {
    val width=width
    override fun convert(holder: BaseViewHolder, item: HomeIntegralBean) {
        var llItem= holder.getView<RoundLinearLayout>(R.id.llItem)
        val para1 = llItem.layoutParams
        para1.width = StringUtil.dp2px((width/2)).toInt()  - StringUtil.dp2px(13f).toInt()
        llItem.layoutParams = para1

        val image = holder.getView<RoundedImageView>(R.id.image)
        GlideUtil.ImageLoad(image.context,item.images,image)
        val img = image.layoutParams
        if (holder.position%2 == 0){
            img.height = StringUtil.dp2px(165f).toInt()
            image.layoutParams=img
        }else{
            img.height = StringUtil.dp2px(180f).toInt()
            image.layoutParams=img
        }
        holder.setText(R.id.tvTitle,item.title)
            .setText(R.id.tvPrice,item.price.toString())
            .setText(R.id.tvOriprice,item.oriprice.toString()+"积分")
        if(!TextUtils.isEmpty(item.oriprice))
            holder.getView<TextView>(R.id.tvOriprice).paint.flags = Paint.STRIKE_THRU_TEXT_FLAG

        GlideUtil.ImageLoad(image.context,item.headimg,holder.getView(R.id.headimg))
        holder.setText(R.id.nickname,item.nickname)
    }
}